package com.zzy.order.service.impl;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.zzy.commonutils.ordervo.CourseWebVoOrder;
import com.zzy.commonutils.ordervo.UcenterMemberOrder;
import com.zzy.order.client.EduClient;
import com.zzy.order.client.UcenterClient;
import com.zzy.order.entity.Order;
import com.zzy.order.mapper.OrderMapper;
import com.zzy.order.service.OrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author KAZU
 * @since 2023-01-23
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
	
	@Autowired
	private OrderMapper orderMapper;
	
	@Autowired
	private EduClient eduClient;
	
	@Autowired
	private UcenterClient ucenterClient;
	
	/**
	 * 生成订单方法
	 * */
	@Override
	public String createOrders(String courseId, String memberId) {
		// 通过远程调用获取用户信息，根据用户id
		UcenterMemberOrder userInfoOrder = ucenterClient.getUserInfoOrder(memberId);
		// 通过远程调用获取课程信息，根据课程id
		CourseWebVoOrder courseInfoOrder = eduClient.getCourseInfoOrder(courseId);
		// 创建order对象，向order对象里面设置需要的数据
		Order order = new Order();
		order.setOrderNo(IdWorker.getIdStr());
		order.setCourseId(courseId);
		order.setCourseTitle(courseInfoOrder.getTitle());
		order.setCourseCover(courseInfoOrder.getCover());
		order.setTeacherName(courseInfoOrder.getTeacherName());
		order.setTotalFee(courseInfoOrder.getPrice());
		order.setMemberId(memberId);
		order.setMobile(userInfoOrder.getMobile());
		order.setNickname(userInfoOrder.getNickname());
		// 未支付
		order.setStatus(0);
		// 支付：微信
		order.setPayType(1);
		orderMapper.insert(order);
		return order.getOrderNo();
	}
}
















